<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <div>柯里化</div>
    <p>柯里化的概念</p>
    <p>
      1.当一个函数有多个参数的时候先传递一部分参数调用它(这部分参数以后永远不变)
    </p>
    <p>2.然后返回一个新的函数接收新的函数接收剩余的参数，返回结果</p>
    <script>
      //硬编码
      function checkAge1(age) {
        let min = 18;
        return age >= min;
      }

      //普通的纯函数
      function checkAge2(min, age) {
        return age >= min;
      }

      console.log(checkAge2(18, 20));
      console.log(checkAge2(18, 24));
      console.log(checkAge2(22, 24));

      //函数柯里化
      function checkAge3(min) {
        return function (age) {
          return age >= min;
        };
      }

      let checkAge18 = checkAge3(18);
      let checkAge20 = checkAge3(20);
      console.log(checkAge18(18));
      console.log(checkAge18(24));
      console.log(checkAge20(18));
      console.log(checkAge20(24));

      //   es6的写法
      let cheakAge4 = (min) => (age) => age >= min;
      let checkage18 = cheakAge4(18);
      let checkage20 = cheakAge4(20);
      console.log(checkage18(18));
      console.log(checkage18(24));
      console.log(checkage20(18));
      console.log(checkage20(24));
    </script>
  </body>
</html>
